using System;
using System.Linq;
using System.Data;
using System.Collections.Generic;

namespace Green.AgileMapper
{
     public static partial class AgileMapperMapping
    {
        /// <summary>
        /// Green.AgileMapper.Test.KeyValuePairDto  Warp fromObj Green.AgileMapper.Test.KeyValuePair;
        /// </summary>
        /// <param name="domainObj">Green.AgileMapper.Test.KeyValuePair</param>
        /// <returns>Green.AgileMapper.Test.KeyValuePairDto</returns>
        public static  Green.AgileMapper.Test.KeyValuePairDto Warp(this Green.AgileMapper.Test.KeyValuePair domainObj)
        {
            var fromObj = new Green.AgileMapper.Test.KeyValuePairDto();
            fromObj.Key = domainObj.Key;
            fromObj.Value = domainObj.Value;
            return fromObj;
        }
        
        /// <summary>
        /// Green.AgileMapper.Test.KeyValuePairDto  Warp domainObj Green.AgileMapper.Test.KeyValuePair;
        /// </summary>
        /// <param name="domainObj">Green.AgileMapper.Test.KeyValuePair</param>
        /// <returns>fromObj</returns>
        public static void Warp(this Green.AgileMapper.Test.KeyValuePairDto fromObj, Green.AgileMapper.Test.KeyValuePair domainObj)
        {
			if(fromObj == null )
            {
             return ;
            }
            if(domainObj == null )
            {
            domainObj = new Green.AgileMapper.Test.KeyValuePair();
            }
            domainObj.Key = fromObj.Key ;
            domainObj.Value = fromObj.Value ;

        }

        /// <summary>
        /// Green.AgileMapper.Test.KeyValuePairDto collection Warp fromObj Green.AgileMapper.Test.KeyValuePair collection;
        /// </summary>
        /// <param name="form">Green.AgileMapper.Test.KeyValuePairDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.KeyValuePair collection</param>        
        public static List<Green.AgileMapper.Test.KeyValuePairDto> Warp(this IList< Green.AgileMapper.Test.KeyValuePair> domainObj)
        {
            List<Green.AgileMapper.Test.KeyValuePairDto> froms = new List<Green.AgileMapper.Test.KeyValuePairDto>();
            domainObj.ToList().ForEach(t =>
            {
                froms.Add(Warp(t));
            });
            return froms;
        }

        /// <summary>
        /// Green.AgileMapper.Test.KeyValuePairDto collection Warp domainObj Green.AgileMapper.Test.KeyValuePair collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.KeyValuePairDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.KeyValuePair collection</param>      
         public static void Warp(this IList<Green.AgileMapper.Test.KeyValuePairDto> fromObj, IList<Green.AgileMapper.Test.KeyValuePair> domainObj)
         {
               fromObj.Warp(domainObj,(fromObjItem,domainObjItem) => fromObjItem.Equals(domainObjItem),false);
         }   

        /// <summary>
        /// Green.AgileMapper.Test.KeyValuePairDto collection Warp domainObj Green.AgileMapper.Test.KeyValuePair collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.KeyValuePairDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.KeyValuePair collection</param>
        /// <param name="isDeleteNotInFromItem">Delete the item that not in From collection</param>           
         public static void Warp(this IList<Green.AgileMapper.Test.KeyValuePairDto> fromObj, IList<Green.AgileMapper.Test.KeyValuePair> domainObj,bool isDeleteNotInFromItem)
         {
               fromObj.Warp(domainObj,(fromObjItem,domainObjItem) => fromObjItem.Equals(domainObjItem),isDeleteNotInFromItem);
         }   

        /// <summary>
        /// Green.AgileMapper.Test.KeyValuePairDto collection Warp domainObj Green.AgileMapper.Test.KeyValuePair collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.KeyValuePairDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.KeyValuePair collection</param>
        /// <param name="equalPredicate">the from item equal to item expression</param>           
         public static void Warp(this IList<Green.AgileMapper.Test.KeyValuePairDto> fromObj, IList<Green.AgileMapper.Test.KeyValuePair> domainObj,Func<Green.AgileMapper.Test.KeyValuePairDto, Green.AgileMapper.Test.KeyValuePair, bool> equalPredicate)
         {
               fromObj.Warp(domainObj,equalPredicate,false);
         }   

        /// <summary>
        /// Green.AgileMapper.Test.KeyValuePairDto collection Warp domainObj Green.AgileMapper.Test.KeyValuePair collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.KeyValuePairDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.KeyValuePair collection</param> 
        /// <param name="equalPredicate">the from item equal to item expression</param>      
        /// <param name="isDeleteNotInFromItem">Delete the item that not in From collection</param>     
         public static void Warp(this IList<Green.AgileMapper.Test.KeyValuePairDto> fromObj, IList<Green.AgileMapper.Test.KeyValuePair> domainObj, Func<Green.AgileMapper.Test.KeyValuePairDto, Green.AgileMapper.Test.KeyValuePair, bool> equalPredicate,bool isDeleteNotInFromItem)
         {
             if(fromObj==null)
             {
                return ;
             }

             if (domainObj == null)
             {
                 domainObj = new List<Green.AgileMapper.Test.KeyValuePair>();
             }
            
            if (isDeleteNotInFromItem)
            {
                domainObj.Where(domainObjItem => fromObj.FirstOrDefault(fromObjItem => equalPredicate(fromObjItem, domainObjItem)) == null)
                    .ToList().ForEach(t =>
                    {
                        domainObj.Remove(t);
                    });
            }

             fromObj.ToList().ForEach(fromObjItem =>
             {
                 Green.AgileMapper.Test.KeyValuePair toItem = default(Green.AgileMapper.Test.KeyValuePair);
                 if (equalPredicate != null)
                 {
                     toItem = domainObj.SingleOrDefault(domainObjItem => equalPredicate(fromObjItem,domainObjItem));
                 }
                 if (toItem == null)
                 {
                     toItem = new Green.AgileMapper.Test.KeyValuePair();
                     domainObj.Add(toItem);
                 }
                 Warp(fromObjItem, toItem);
             });
                      
         }
    }
}